import os
import cv2
import glob
import sys
from collections import OrderedDict

fps = 24

img_root = "./"
out_dir = "./"
RES = (832, 448)
imgs = glob.glob(os.path.join(img_root, "*.png"))
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
video_writer = cv2.VideoWriter(os.path.join(out_dir, "rearHLDetResults_no_fr"+".avi"), fourcc, fps, RES)

imgs_dict = {}
for img in imgs:
    img_id = img.split('/')[-1].split('_V')[0]
    img_id = img_id.replace('-', '')
    imgs_dict[img_id] = img

imgs_dict = OrderedDict(sorted(imgs_dict.items(), key=lambda t:t[0]))

count = 0
for img in imgs_dict.values():
    frame = cv2.imread(img)
    video_writer.write(frame)
    count += 1
    if count % 200 == 0:
        print(count, " images processed.")

video_writer.release()
print("done...")
